
namespace Core {
    export class BaseSpriteView extends Laya.Sprite implements IBaseView {

        private _controller: BaseController;
        private _myParent: Laya.Sprite;
        private _isInit: boolean;
        private _resources: string[] = null;

        public constructor(controller: BaseController, parent: Laya.Sprite) {
            super()
            this._controller = controller
            this._myParent = parent
            this._isInit = false
            App.StageUtils.getStage().on(Laya.Event.RESIZE, this, this.onResize);

        }

        public setResources(resources: string[]): void {
            this._resources = resources;
        }

        public get myParent(): Laya.Sprite {
            return this._myParent;
        }

        public isInit(): boolean {
            return this._isInit;
        }

        public applyFunc(key: any, ...param: any[]): any {
            return this._controller.applyFunc.apply(this._controller, arguments);
        }

        public applyControllerFunc(controllerKey: number, key: any, ...param: any[]): any {
            return this._controller.applyControllerFunc.apply(this._controller, arguments);
        }

        public isShow(): boolean {
            return this.stage != null && this.visible;
        }

        public addToParent(): void {
            this._myParent.addChild(this);
        }

        public removeFromParent(): void {
            App.DisplayUtils.removeFromParent(this);
        }

        public initUI(): void {
            this._isInit = true;
        }
        public initData(): void {
        }
        public open(...param: any[]): void {
        }
        public close(...param: any[]): void {
        }
        public destroy(): void {
            this._controller = null;
            this._myParent = null;
            this._resources = null;
        }
        public setVisible(value: boolean): void {
            this.visible = value;
        }

        public loadResource(loadComplete: Function, initComplete: Function): void {
            if (this._resources && this._resources.length > 0) {
                App.ResourceUtils.loadResource(this._resources, function (): void {
                    loadComplete();
                    initComplete();
                }, null, this);
            }
            else {
                loadComplete();
                initComplete();
            }
        }

        protected onResize(): void {
        }
    }
}